package zhtt04.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhtt04.dao.User04Dao;
import zhtt04.entity.User04;

/**
 * Created by zhtt on 2016/10/31.
 */
@RestController
@RequestMapping("user4")
public class User04Controller {

    @Autowired    private User04Dao dao;

    @RequestMapping("/get/{id}")
    private Object get(@PathVariable("id") int id) {
        try{
            return dao.findOne(id);
//            return "查询成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @RequestMapping("/save/{name}/{email}")
    private Object save(@PathVariable("name") String name,@PathVariable("email") String email) {
        try{
            User04 user=new User04();
            user.setName(name);
            user.setEmail(email);
            dao.save(user);
            return "保存成功！";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }
}
